#include "translate.h"

#include "ir.h"

shared_ptr<Tree::Exp> Translate::translate(shared_ptr<Exp> exp) {
	switch(exp->getType()) {
		case OrType:
			return translate(shared_static_cast<OrExp>(exp));
		case AndType:
			return translate(shared_static_cast<AndExp>(exp));
		case LessThanType:
			return translate(shared_static_cast<LessThanExp>(exp));
		case GreaterThanType:
			return translate(shared_static_cast<GreaterThanExp>(exp));
		case DifferentType:
			return translate(shared_static_cast<DifferentExp>(exp));
		case EqualType:
			return translate(shared_static_cast<EqualExp>(exp));
		case PlusType:
			return translate(shared_static_cast<PlusExp>(exp));
		case MinusType:
			return translate(shared_static_cast<MinusExp>(exp));
		case TimesType:
			return translate(shared_static_cast<TimesExp>(exp));
/*		case ArrayValueType:
			return translate(shared_static_cast<ArrayValueExp>(exp));
		case ArrayLengthType:
			return translate(shared_static_cast<ArrayLengthExp>(exp));
		case MemberFunctionType:
			return translate(shared_static_cast<MemberFunctionExp>(exp));
		case NewIntArrayType:
			return translate(shared_static_cast<NewIntArrayExp>(exp));
		case NewIdType:
			return translate(shared_static_cast<NewIdExp>(exp));
*/
		case NotType:
			return translate(shared_static_cast<NotExp>(exp));
		case NumberType:
			return translate(shared_static_cast<NumberExp>(exp));
		case TrueType:
			return translate(shared_static_cast<TrueExp>(exp));
		case FalseType:
			return translate(shared_static_cast<FalseExp>(exp));
/*		case IdType:
			return translate(shared_static_cast<IdExp>(exp));
		case ThisType:
			return translate(shared_static_cast<ThisExp>(exp));
*/
		default:
			break;
	}
}

shared_ptr<Tree::Exp> Translate::translate(shared_ptr<OrExp> orExp) {
	return shared_ptr<Tree::Binop>(new Tree::Binop(Tree::Or, translate(orExp->exp1), translate(orExp->exp2)));
}

shared_ptr<Tree::Exp> Translate::translate(shared_ptr<AndExp> andExp) {
	return shared_ptr<Tree::Binop>(new Tree::Binop(Tree::And, translate(andExp->exp1), translate(andExp->exp2)));
}

shared_ptr<Tree::Exp> Translate::translate(shared_ptr<PlusExp> plusExp) {
	return shared_ptr<Tree::Binop>(new Tree::Binop(Tree::Plus, translate(plusExp->exp1), translate(plusExp->exp2)));
}

shared_ptr<Tree::Exp> Translate::translate(shared_ptr<MinusExp> minusExp) {
	return shared_ptr<Tree::Binop>(new Tree::Binop(Tree::Minus, translate(minusExp->exp1), translate(minusExp->exp2)));
}

shared_ptr<Tree::Exp> Translate::translate(shared_ptr<TimesExp> timesExp) {
	return shared_ptr<Tree::Binop>(new Tree::Binop(Tree::Times, translate(timesExp->exp1), translate(timesExp->exp2)));
}

shared_ptr<Tree::Exp> Translate::translate(shared_ptr<NumberExp> numberExp) {
	return shared_ptr<Tree::Const>(new Tree::Const(numberExp->value));
}

shared_ptr<Tree::Exp> Translate::translate(shared_ptr<TrueExp> trueExp) {
	return shared_ptr<Tree::Const>(new Tree::Const(1));
}

shared_ptr<Tree::Exp> Translate::translate(shared_ptr<FalseExp> falseExp) {
	return shared_ptr<Tree::Const>(new Tree::Const(0));
}



